const { assert, expect } = require('chai');
const { ethers } = require('hardhat');

// Vanilla Mocha test. Increased compatibility with tools that integrate Mocha.
// describe("SimpleStorage", () => {})
describe('SimpleStorage', function () {
    let simpleStorageFactory;
    let simpleStorageContract;

    beforeEach(async function () {
        // Get the contract factory
        simpleStorageFactory = await ethers.getContractFactory('SimpleStorage');
        simpleStorageContract = await simpleStorageFactory.deploy();
        await simpleStorageContract.waitForDeployment();
    });

    it('Should start with a favorite number of 0', async function () {
        const currentFavoriteNumber = await simpleStorageContract.retrieve();

        // assert.equal(currentFavoriteNumber, 0);
        // expect(currentFavoriteNumber == 10).to.be.false;
        // expect(currentFavoriteNumber == 0).to.be.true;
        expect(currentFavoriteNumber).to.equal(0);
    });

    it('Should update when we call store', async function () {
        const newFavoriteNumber = 13;
        let transactionResponse =
            await simpleStorageContract.store(newFavoriteNumber);
        await transactionResponse.wait(1);

        const currentFavoriteNumber = await simpleStorageContract.retrieve();

        assert.equal(currentFavoriteNumber, newFavoriteNumber);
    });

    it('Should work correctly with the people struct and array', async function () {
        // Add a person
        let expectPersionName = 'Alice';
        let expectFavoriteNumber = '23';
        let transactionResponse = await simpleStorageContract.addPerson(
            expectPersionName,
            expectFavoriteNumber,
        );
        await transactionResponse.wait(1);

        // Check the person
        const person = await simpleStorageContract.people(0);
        assert.equal(person.name, expectPersionName);
        assert.equal(person.favoriteNumber, expectFavoriteNumber);
    });
});
